package guggaTests.tasks
{
	import flash.events.Event;
	
	import flexunit.framework.Assert;
	import flexunit.framework.TestCase;
	
	import gugga.tasks.CustomCompleteTask;
	import gugga.tasks.events.TaskEvent;

	public class CustomCompleteTaskTest extends TestCase
	{
		
		private var mCustomCompleteTaskEventDispatched : Boolean = false;
		
		public function CustomCompleteTaskTest(methodName:String=null)
		{
			super(methodName);
		}
		
		public function testEventDispatching() : void
		{
			var task : CustomCompleteTask = new CustomCompleteTask;
			
			task.addEventListener(TaskEvent.START, customCompleteTaskEventFunction);
			task.addEventListener(TaskEvent.INTERRUPTED, customCompleteTaskEventFunction);
			task.addEventListener(TaskEvent.COMPLETED, customCompleteTaskEventFunction);			
			
			assertFalse(
				"task shouldn't be running",
				task.isRunning());
			
			task.start()
			
			assertTrue(
				"task should be running, it's started",
				task.isRunning());
				
			assertTrue(
				"startEvent should be dispatched",
				mCustomCompleteTaskEventDispatched);
			
			mCustomCompleteTaskEventDispatched = false;	
			task.interrupt();
			
			assertFalse(
				"task shouldn't be running, it's interrupted",
				task.isRunning());
				
			assertTrue(
				"interruptEvent should be dispatched",
				mCustomCompleteTaskEventDispatched);
				
			mCustomCompleteTaskEventDispatched = false;	
			task.complete();
			
			assertFalse(
				"task shouldn't be running, it's interrupted",
				task.isRunning());
				
			assertTrue(
				"interruptEvent should be dispatched",
				mCustomCompleteTaskEventDispatched);
		}
		
		public function customCompleteTaskEventFunction(aEvent : Event) : void
		{
			mCustomCompleteTaskEventDispatched = true;
		}
	}
}